package stz.flash.main;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
import stz.flash.main.strobe.field.StrobeControlBar;
import blackberry.util.DjColorData;
import blackberry.util.field.DjLabelField;

public class HotkeyAdviceManager extends Manager {
	
	public static final int FONT_COLOR = Color.BEIGE;
	public static final int FONT_GLOBAL_ALPHA = 200;
	public static final int FONT_HEIGHT_pt = 4;
	
	private static final Background BACKGROUND = BackgroundFactory.createSolidTransparentBackground(
			Color.FORESTGREEN, 200);
	private static final Border BORDER = BorderFactory.createSimpleBorder(
			new XYEdges(2, 2, 2, 2), 
			new XYEdges(Color.GREEN, Color.DARKGREEN, Color.DARKGREEN, Color.GREEN), 
			Border.STYLE_SOLID);
	
	private static DjLabelField L = createHotkeyLabel("L");
	private static DjLabelField B = createHotkeyLabel("B");
	private static DjLabelField Space = createHotkeyLabel("Space");
	private static DjLabelField R_VolumeUp_VolumeDown = createHotkeyLabel("R_VolumeUp_VolumeDown");
	
	private static DjLabelField VolumeUp_controlBar = createHotkeyLabel("VolumeUp");
	private static DjLabelField VolumeDown_controlBar = createHotkeyLabel("VolumeDown");
	
	private TimerField timerField;
	
	

	public HotkeyAdviceManager(TimerField timerField) {
		super(0);
		this.timerField = timerField;
		
		add(L);
		add(B);
		add(Space);
		add(R_VolumeUp_VolumeDown);
		
		add(VolumeUp_controlBar);
		add(VolumeDown_controlBar);
	}
	
	/**
	 * 화면에 표시될 LabelField 의 생성 메서드 
	 */
	public static DjLabelField createHotkeyLabel(String label){
		DjLabelField hotkeyLabel = DjLabelField.createColorNewFontLabel(
				label, 
				new DjColorData(FONT_COLOR, FONT_GLOBAL_ALPHA),
				Font.getDefault().derive(Font.PLAIN, FONT_HEIGHT_pt, Ui.UNITS_pt),
				0);
		hotkeyLabel.setBackground(BACKGROUND);
		hotkeyLabel.setBorder(BORDER);
		
		return hotkeyLabel; 
	}
	
	public static DjLabelField getL() {
		return L;
	}

	public static DjLabelField getB() {
		return B;
	}

	public static DjLabelField getSpace() {
		return Space;
	}

	public static DjLabelField getR_VolumeUp_VolumeDown() {
		return R_VolumeUp_VolumeDown;
	}

	public static DjLabelField getVolumeUp() {
		return VolumeUp_controlBar;
	}

	public static DjLabelField getVolumeDown() {
		return VolumeDown_controlBar;
	}
	
	protected void sublayout(int width, int height) {
		setExtent(MainManager.WIDTH, Display.getHeight());
		
		setPositionChild(
				L, 
				ImageXY.L_hotkey[0], 
				ImageXY.L_hotkey[1]);
		layoutChild(
				L, 
				getPreferredWidthOfChild(L), 
				getPreferredHeightOfChild(L));
		
		setPositionChild(
				B, 
				ImageXY.B_hotkey[0], 
				ImageXY.B_hotkey[1]);
		layoutChild(B, 
				getPreferredWidthOfChild(B), 
				getPreferredHeightOfChild(B));

		setPositionChild(
				Space, 
				ImageXY.SPACE_hotkey[0], 
				ImageXY.SPACE_hotkey[1]);
		layoutChild(
				Space, 
				getPreferredWidthOfChild(Space), 
				getPreferredHeightOfChild(Space));
		
		setPositionChild(
				R_VolumeUp_VolumeDown, 
				timerField.getLeft() + getPreferredWidthOfChild(timerField), 
				(timerField.getTop() + getPreferredHeightOfChild(timerField)) 
						- getPreferredHeightOfChild(R_VolumeUp_VolumeDown));
		layoutChild(
				R_VolumeUp_VolumeDown, 
				getPreferredWidthOfChild(R_VolumeUp_VolumeDown), 
				getPreferredHeightOfChild(R_VolumeUp_VolumeDown));
		
		
		setPositionChild(
				VolumeUp_controlBar, 
				MainManager.WIDTH - getPreferredWidthOfChild(VolumeUp_controlBar),
				StrobeControlBar.getIns().getTop() - getPreferredHeightOfChild(VolumeUp_controlBar));
		layoutChild(
				VolumeUp_controlBar, 
				getPreferredWidthOfChild(VolumeUp_controlBar), 
				getPreferredHeightOfChild(VolumeUp_controlBar));
		
		setPositionChild(
				VolumeDown_controlBar, 
				MainManager.WIDTH - getPreferredWidthOfChild(VolumeDown_controlBar), 
				StrobeControlBar.getIns().getTop() 
						+ getPreferredHeightOfChild(StrobeControlBar.getIns()));
		layoutChild(
				VolumeDown_controlBar, 
				getPreferredWidthOfChild(VolumeDown_controlBar), 
				getPreferredHeightOfChild(VolumeDown_controlBar));
	}
}